package com.tjsinfo.tjsoa.address.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.address.personal.TAddresslistPersonal;
import com.tjsinfo.tjsoa.address.personal.TAddresslistPersonalManager;
import com.tjsinfo.tjsoa.system.vo.User;

public class PersonalListFindAction extends Action {
	
    TAddresslistPersonalManager addresslistPersonalManager;
	
	public TAddresslistPersonalManager getAddresslistPersonalManager() {
		return addresslistPersonalManager;
	}

	public void setAddresslistPersonalManager(
			TAddresslistPersonalManager addresslistPersonalManager) {
		this.addresslistPersonalManager = addresslistPersonalManager;
	}
	
	@SuppressWarnings("unchecked")
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {	
			request.setCharacterEncoding("UTF-8");
			
			HttpSession session=request.getSession();
			User tsui=(User)session.getAttribute("user");
						
			String chinesename=request.getParameter("chinese_name");
            String department=request.getParameter("department");
            String userId=request.getParameter("userId");
            String cid = request.getParameter("cid");
            
			if (cid.equals("1")){
				chinesename=new String(chinesename.getBytes("ISO8859_1"),"UTF-8");
				department=new String(department.getBytes("ISO8859_1"),"UTF-8");
			}            
			
            request.setAttribute("chinese_name", chinesename);
            request.setAttribute("department", department);
            request.setAttribute("userId", userId);
            List<TAddresslistPersonal> personal=addresslistPersonalManager.findList("chineseName", "%"+chinesename+"%", "department", "%"+department+"%","userId",userId);
            request.setAttribute("personal", personal);
                     
            
			return mapping.findForward("success");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("failed");
		}
	}
}

